import sys

class UnionFind:
    def __init__(self, size):
        self.parent = list(range(size + 1))  # 元素从1到size
        self.rank = [1] * (size + 1)
    
    def find(self, x):
        parent = self.parent
        while parent[x] != x:
            parent[x] = parent[parent[x]]  # 路径压缩
            x = parent[x]
        return x
    
    def union(self, x, y):
        parent = self.parent
        rank = self.rank
        root_x = self.find(x)
        root_y = self.find(y)
        if root_x == root_y:
            return
        if rank[root_x] > rank[root_y]:
            parent[root_y] = root_x
        else:
            parent[root_x] = root_y
            if rank[root_x] == rank[root_y]:
                rank[root_y] += 1

def main():
    data = list(map(int, sys.stdin.read().split()))
    ptr = 0
    n = data[ptr]
    ptr += 1
    m = data[ptr]
    ptr += 1
    uf = UnionFind(n)
    res = []
    for _ in range(m):
        opt = data[ptr]
        x = data[ptr + 1]
        y = data[ptr + 2]
        ptr += 3
        if opt == 1:
            if uf.find(x) == uf.find(y):
                res.append("Yes")
            else:
                res.append("No")
        elif opt == 2:
            uf.union(x, y)
    print('\n'.join(res))

if __name__ == "__main__":
    main()